package org.bmind.datasword.utils.setup;

import java.util.HashMap;
import java.util.Map;

import org.bmind.datasword.config.dto.DChildDatasetContainer;
import org.bmind.datasword.config.dto.DConfig;
import org.bmind.datasword.config.dto.DMonoAnalisys;
import org.bmind.datasword.config.dto.DMultiAnalisysContainer;
import org.bmind.datasword.config.dto.DParentDatasetContainer;
import org.bmind.datasword.config.dto.DPreProcess;
import org.bmind.datasword.config.impl.orient.OrientDConfig;
import org.bmind.datasword.config.impl.orient.OrientDataset;
import org.bmind.datasword.config.impl.orient.OrientMonoAnalisys;
import org.bmind.datasword.config.impl.orient.OrientMultiAnalisysContainer;
import org.bmind.datasword.config.impl.orient.OrientPreProcess;

import com.orientechnologies.orient.core.db.object.ODatabaseObject;
import com.orientechnologies.orient.core.db.object.ODatabaseObjectTx;

public class Pojo2Ordb {
	private static ODatabaseObject orDb;
	
	public Pojo2Ordb() {super();}
	
	/**
	 * 
	 * @param parameters
	 * @throws Exception
	 */
	public static void init(Map<String, Object> parameters) throws Exception {

		if (parameters.containsKey("url")) {
			orDb = new ODatabaseObjectTx((String) parameters.get("url"));

			if (parameters.containsKey("user")) {
				if (parameters.containsKey("password")) {
					orDb.open((String) parameters.get("user"),
							(String) parameters.get("password"));
				}
			}
		}
	}
	
	/**
	 * 
	 * @param dmonoanalisys
	 */
	public static void dMonoAnalisys(DMonoAnalisys dmonoanalisys){
		OrientMonoAnalisys oma = new OrientMonoAnalisys(orDb);
		orDb.save(dmonoanalisys);
	}
	
	/**
	 * 
	 * @param dmultianalisys
	 */
	
	public static void dMultiAnalisysContainer(DMultiAnalisysContainer dMultianAlisysContainer){
		OrientMultiAnalisysContainer omu = new OrientMultiAnalisysContainer(orDb);
		orDb.save(dMultianAlisysContainer);
	}
	
	/**
	 * 
	 * @param rpreprocess
	 */
	public static void dPreProcess(DPreProcess dpreproc){
		OrientPreProcess opp = new OrientPreProcess(orDb);
		orDb.save(dpreproc);
	}
	
	
	/**
	 * 
	 * @param dlistdataset
	 */
	public static void dChildDatasetContainer(DChildDatasetContainer dlistdataset){
		OrientDataset ods = new OrientDataset(orDb);
		orDb.save(dlistdataset);
	}
	
	/**
	 * 
	 * @param dlistdataset
	 */
	public static void dParentDatasetContainer(DParentDatasetContainer dlistlistdataset){
		OrientDataset ods = new OrientDataset(orDb);
		orDb.save(dlistlistdataset);
	}
	
    /**
     * 
     * @param dconfig
     */
	public static void dConfig(DConfig dconfig){
		OrientDConfig odc = new OrientDConfig(orDb);
		odc.removeConfig(orDb);
		orDb.save(dconfig);
	//	Map<String,String> test = new HashMap<String, String>();
	//	test.put("Ruggeri", "Valerio");
	//	test.put("Breda", "Marco");
	//	orDb.save(test); 
	}

}
